package com.hz.winnie.demands.service;

import java.util.List;

import com.hz.winnie.demands.dao.UserDao;
import com.hz.winnie.demands.pojo.Role;
import com.hz.winnie.demands.pojo.User;

/**
 * @description 用户服务类
 * @author winnie
 * @date 2011-4-3
 * @version 1.0
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    /*
     * (non-Javadoc)
     * 
     * @see com.hz.winnie.demands.service.UserService#authUser(java.lang.String,
     * java.lang.String)
     */
    @Override
    public User authUser(String userName, String password) {
	User user = userDao.getUserByNameAndPassword(userName, password);
	return user;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.service.UserService#getUserById(java.lang.String)
     */
    @Override
    public User getUserById(String userId) {
	User user = userDao.getUserById(userId);
	return user;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.service.UserService#getUsersByRoleId(java.lang.
     * String)
     */
    @Override
    public List<User> getUsersByRole(Role role) {
	List<User> users = userDao.getUsersByRole(role.toString());
	return users;
    }

    /**
     * @return the userDao
     */
    public UserDao getUserDao() {
	return userDao;
    }

    /**
     * @param userDao
     *            the userDao to set
     */
    public void setUserDao(UserDao userDao) {
	this.userDao = userDao;
    }

    @Override
    public int addUser(User user) {
	return userDao.insert(user);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.service.UserService#editUser(com.hz.winnie.demands
     * .pojo.User)
     */
    @Override
    public void editUser(User user) {
	userDao.edit(user);
    }

}
